<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Update Classrooms</title>
</head>

<body>

<?php
$building_id = $_GET['id'];
$building_name = $_GET['name'];
$abbreviation = $_GET['abbrev'];

echo "<h1>UNO Course Scheduler - $building_name Classrooms Portal</h1>";

//initialize variables used to connect to database
$db = "scheduler";
$user = "root";
$pass = "";

//counting variable
$i = 0;

//connect to database
mysql_connect("localhost", $user, $pass);
@mysql_select_db($db);

//select statement
$query="SELECT * FROM classrooms WHERE building_id = $building_id";
$result=mysql_query($query);

//determine dynamically number of rows read from table
$num_rows=mysql_numrows($result);

echo '<p>';

//start table
echo "<table border='0'>";
	
	//create table row with column ID's
	echo "<tr>";
		echo "<td width ='100'><b>Room</b></td>";
		echo "<td width ='200'><b>Type</b></td>";
		echo "<td width ='100' style='text-align: center'><b>Seats</b></td>";
		echo "<td></td>";
		echo "<td></td>";
	echo "</tr>";

//loop to walk through and print to screen all entries in classrooms table
while ($i < $num_rows) 
{
	//store each classroomname and abbreviation in a scalar
	$classroom_id=mysql_result($result,$i,"id");
	$room_num=mysql_result($result,$i,"room_num");
	$num_seats=mysql_result($result,$i,"num_seats");
	$classroom_type_id=mysql_result($result,$i,"classroom_type_id");

	$query2="SELECT * FROM classroom_types WHERE id = $classroom_type_id";
	$result2=mysql_query($query2);
	$type_description=mysql_result($result2,0,"description");
	
	//generate table row for each classroomon each iteration of the loop
	echo "<tr>";
		echo "<td>$abbreviation $room_num</td>";		//classroomname cell
		echo "<td>$type_description</td>";		//classroomabbreviation cell
		echo "<td style='text-align: center'>$num_seats</td>";
		echo "<td>";		//cell containing form for edit classroomlink/button
			echo "<form method='get' action='edit.php'>";
				echo "<input type='hidden' name='bid' value='$building_id'>";
				echo "<input type='hidden' name='name' value='$building_name'>";
				echo "<input type='hidden' name='abbrev' value='$abbreviation'>";
				echo "<input type='hidden' name='room_num' value='$room_num'>";
				echo "<input type='hidden' name='num_seats' value='$num_seats'>";
				echo "<input type='hidden' name='type' value='$type_description'>";
				echo "<input type='hidden' name='ctid' value='$classroom_type_id'>";
				echo "<input type='hidden' name='id' value='$classroom_id'>";
				echo "<input type='Submit' value='Edit'>";
			echo "</form>";
		echo "</td>";
		
		echo "<td>";		//cell containing form for delete classroomlink/button
			echo "<form method='get' action='delete.php'>";
				echo "<input type='hidden' name='bid' value='$building_id'>";
				echo "<input type='hidden' name='name' value='$building_name'>";
				echo "<input type='hidden' name='abbrev' value='$abbreviation'>";
				echo "<input type='hidden' name='id' value='$classroom_id'>";
				echo "<input type='Submit' value='Delete'>";
			echo "</form>";
		echo "</td>";
	
	echo "</tr>";
		
	//increment counting variable
	$i++;
}

//end table tag
echo "</table>";

//close
mysql_close();

echo '</p>';

echo '<p>';

//creates link/button for add building
echo "<form method='get' action='add.php'>";
	echo "<input type='hidden' name='id' value='$num_rows'>";
	echo "<input type='hidden' name='bid' value='$building_id'>";
	echo "<input type='hidden' name='name' value='$building_name'>";
	echo "<input type='hidden' name='abbrev' value='$abbreviation'>";
	echo "<input type='Submit' value='Add Classroom'>";
echo "</form>";

echo '</p>';

?>

<p>
	<a href="../">&lt;&lt; Back to Buildings Portal</a>
</p>
</body>
</html>